@extends('Layout/adminBase')
@section('css')
<link rel="stylesheet" type="text/css" href="{{asset('/bootstrap/css/bootstrap.min.css')}}">
<style type="text/css">
    .head-div{
        height: 70px;
    }
    .head-div .head-left{
        margin-left:20px;
    }
 
    .main-div{
        padding:50px;
    }
    .main-div .main-form{
        margin-left:230px;
    }
    .middle{
        height: 20px;
        background: #d5d5d8;
    }

</style>
@endsection
@section('body')
	<div class="head-div">
		<div class='head-left'>
		    <h4>添加积分商品</h4>
		</div>
		</div>
		
		<div class="main-div">
		<form class="form-horizontal main-form" role="form" action="javascript:;">
		@foreach ($status as $v)
			<input type="hidden" name="id" value="{{$v->id}}">
		
		    <div class="form-group">
            	<label for="lastname" class="col-sm-2 control-label">商品状态</label>
	            <div class="col-sm-5">
	                <select name='status'  class="form-control">
	                    <option value="0" <?php echo $state==0?'selected':'';?>>新订单</option>
	                    <option value="1" <?php echo $state==1?'selected':'';?>>已发货</option>
	                    <option value="2" <?php echo $state==2?'selected':'';?>>已收货</option>
	                    <option value="3" <?php echo $state==3?'selected':'';?>>无效订单</option>
	                </select>
	            </div>
        	</div>
        @endforeach
		    <div class="form-group">
		        <div class="col-sm-offset-2 col-sm-5">
		            <a  class="btn btn-success btn-add" >修改</a>
		            
		        </div>
		    </div>
		</form>
	</div>
@endsection

@section('footer-js')

<script>
	
	$('.btn-add').click(function () {

		var id = $('input[name="id"]').val();
		var status = $('select[name="status"]').val();

		//console.log(status);
		var token  = "{{csrf_token()}}";
		$.ajax({ 

			url: "{{url('/admin/integralOrder/orderUpdate')}}",
			type: 'post',
			data: {'id':id, 'status':status, '_token':token},
			datatype: 'json',
			success: function (data) { 
				
				console.log(data);
				if (data.code == 2032) {
	                    var div =  "<div class='alert alert-success alert-mess'>"+data.msg+"</div>";
	                    $('.alert-mess').remove();
	                    $('.main-div').prepend(div);
	                    setTimeout(function () {                 
	                        location.href = "{{url('/admin/integralOrder/order')}}";
	                    }, 1000)
	                } else {
	                    var div =  "<div class='alert alert-danger alert-mess'>"+data.msg+"</div>";
	                    $('.alert-mess').remove();
	                    $('.main-div').prepend(div);
	                }

			},
			error: function (tipString) {
		          	//console.log(tipString.responseText);
		           	var text = JSON.parse(tipString.responseText).errors;
	                var div = "<div class='alert alert-danger alert-mess'><ul>";
	                if (text) {
	                    for (var key in text) {
	                        div += "<li>"+text[key][0]+"</li>";
	                    }
	                } else {
	                    div += "<li>"+"未知错误"+"</li>";
	                }
	                div += '</ul></div>';
	                $('.alert-mess').remove();
	                $('.main-div').prepend(div);
		        },
		});

	})

</script>	

@endsection